package com.fei.wechat.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fei.wechat.admin.aspect.annotation.AnnoOperateLog;
import com.fei.wechat.common.constant.OperateLogConstant;
import com.fei.wechat.common.constant.OperateLogContentTemplate;
import com.fei.wechat.common.model.vo.PagerVo;
import com.fei.wechat.common.model.vo.RespVo;
import com.fei.wechat.middlewar.api.admin.IRoleService;
import com.fei.wechat.middlewar.mode.bo.admin.RoleBo;
import com.fei.wechat.middlewar.mode.vo.admin.CurrentUser;
import com.fei.wechat.middlewar.mode.vo.admin.RoleVo;

/**
 * 描述: 角色管理控制层
 * 版权: Copyright (c) 2018 
 * 公司: 飞翔科技 
 * 作者: 张进飞 
 * 版本: 1.0 
 * 创建日期: 2018年7月8日 
 * 创建时间: 下午9:37:05
 */
@RequestMapping("/admin/role")
@Controller
public class RoleController extends BaseController
{
    
    @Autowired
    private IRoleService roleService;
    
    /**
     * 描述：index页面
     * 作者：张进飞
     * 时间：2018年7月8日 下午9:37:31
     * @param request
     * @return
     */
    @RequestMapping("/index")
    public ModelAndView index(HttpServletRequest request)
    {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("base/role/list");
        return mav;
    }
    
    /**
     * 描述：分页查询角色
     * 作者：张进飞
     * 时间：2018年7月8日 下午10:16:00
     * @param request
     * @param roleBo
     * @return
     */
    @AnnoOperateLog(moduleName = OperateLogConstant.MODULE_SYSMGR, function = OperateLogConstant.FUNCTION_PAGE_ROLE, operateType = OperateLogConstant.OPERATE_ID_QUERY, operateContentTemplate = OperateLogContentTemplate.QUERY_ROLE)
    @RequestMapping("/queryRolePage")
    @ResponseBody
    public RespVo queryRolePage(HttpServletRequest request, @RequestBody RoleBo roleBo)
    {
        RespVo respVo = new RespVo();
        Object[] objArray = new Object[3];
        CurrentUser currentUser = this.getCurrentUser(request);
        String loginName = currentUser.getUser().getLoginName();
        objArray[0] = loginName;
        try
        {
            PagerVo<RoleVo> pager = roleService.queryRoleVoPage(roleBo);
            respVo.setCode(RespVo.CODE_SUCCESS);
            respVo.setMessage("查询成功");
            respVo.setResult(pager);
            objArray[1] = "成功";
        }
        catch (Exception e)
        {
            objArray[1] = "失败";
            respVo.setCode(RespVo.CODE_ERROR);
            respVo.setMessage("查询失败");
            logger.error("查询角色，异常：", e);
        }
        respVo.setLogArgs(objArray);
        return respVo;
    }
}
